﻿using System;
using FxCore.Stuff;

namespace FxCore.Base
{
    /// <summary>
    /// 屏幕显示的像素坐标
    /// </summary>
    public class PixelPoint
    {
        public float PixelX { get; }

        public float PixelY { get; }

        public PixelPoint()
        {
            this.PixelX = 0.0F;
            this.PixelY = 0.0F;
        }

        public PixelPoint(float pixelX, float pixelY)
        {
            this.PixelX = pixelX;
            this.PixelY = pixelY;
        }

        public static bool operator ==(PixelPoint pointA, PixelPoint pointB)
        {
            if (pointA == null || pointB == null)
            {
                throw new NullReferenceException();
            }
            return Helper.CompareFloat(pointA.PixelX, pointB.PixelX) &&
                   Helper.CompareFloat(pointA.PixelY, pointB.PixelY);
        }

        public static bool operator !=(PixelPoint pointA, PixelPoint pointB)
        {
            return !(pointA == pointB);
        }

        public static PixelPoint operator -(PixelPoint pointA, PixelPoint pointB)
        {
            return new PixelPoint(pointA.PixelX-pointB.PixelX, pointA.PixelY-pointB.PixelY);
        }

        public static PixelPoint operator +(PixelPoint pointA, PixelPoint pointB)
        {
            return new PixelPoint(pointA.PixelX+pointB.PixelX, pointA.PixelY+pointB.PixelY);
        }

        public override string ToString()
        {
            return $"像素坐标点:{{PixelX=>{this.PixelX}, PixelY=>{this.PixelY}}}";
        }

        public override bool Equals(object obj)
        {
            PixelPoint tmp = (PixelPoint) obj;
            if (tmp == null)
            {
                throw new NullReferenceException();
            }

            return Helper.CompareFloat(this.PixelX, tmp.PixelX) && Helper.CompareFloat(this.PixelY, tmp.PixelY);
        }

        public override int GetHashCode()
        {
            return this.PixelX.GetHashCode() ^ this.PixelY.GetHashCode();
        }
    }
}
